<template>
<!-- 收货地址 -->
    <div class="myAddress">
        <!-- 顶部 -->
       <div class="addressHeader">
            <!-- <router-link  to="/userInfo" class="header-left vip-icon icon-back" tag="div"></router-link> -->
             <div @click="$router.go(-1)" class="header-left vip-icon icon-back"></div>
            <div class="header-middle">收货地址列表</div>
            <router-link to="/home" tag="div" class="header-right vip-icon icon-home"></router-link>
       </div>
       <!-- 收货地址列表 -->
       <div class="address-lists">
        <!-- 收货地址列表 -->
         <ul class="uls-lists" v-if="addressList">
            <li class="lis-lists" v-for="(item,index) in addressList" :key="index">
                <h4>
                    <span>{{item.name}}</span>
                    <span>{{item.tel}}</span>
                </h4>
                <p class="address-detail">
                    {{item.province}}{{item.city}}{{item.county}}{{item.addressDetail}}
                </p>
                <p class="time-detail">收货时间不限</p>
                <div class="manage-address">
                    <router-link tag="div" :to='"/modifyAddress?id=" + index'>修改</router-link>
                    <div @click="del(index)">删除</div>
                </div>
            </li>
            
         </ul>

         <!-- 收货地址为零 显示 -->
         <van-empty description="请添加收货地址" v-if="addressList.length == 0" />

         <!-- 添加收货地址 -->
         <div class="add-address">
            <router-link tag="div" to="/addMyAddress">添加收货地址</router-link>
         </div>
       </div>
    </div>
</template>

<script>
    export default {
        name:"myAddressView",
        data() {
            return {
                addressList: [],
            };
        },
        methods:{
            del(index){
                // console.log(1111);
                // 删除地址
                this.addressList.splice(index,1);
                // 重新加载localStorage里面的数据
               window.localStorage.setItem("address",JSON.stringify(this.addressList));
            }
        },
        created(){
            if(window.localStorage.getItem("address")){
            this.addressList = JSON.parse(window.localStorage.getItem("address"));
            // console.log(this.addressList);
        }
        }
    }
</script>

<style lang="scss" scoped>
.myAddress{
    background-color: #f3f4f5;
    height: 100%;
    .addressHeader{
        width: 100%;
        height: 44px;
        display: flex;
        align-items: center;
        border-bottom: 1px solid #f2f2f2;
        background-color: #fff;
        .header-left{
            width: 56px;
            height: 44px;
            text-align: center;
            line-height: 44px;
            font-size: 20px;
        }

        .header-middle{
            text-align: center;
            line-height: 44px;
            font-size: 18px;
            flex: 1;
        }
        .header-right{
            font-size: 20px;
            width: 56px;
            height: 44px;
            text-align: center;
            line-height: 44px;
        }
    }
    .address-lists{
        background: #fff;
        
        .uls-lists{
            display: flex;
            flex-direction: column;
            justify-items: center;
            align-items: center;
            .lis-lists{
                width: 100%;
                padding:20px 0 10px 20px;
                height: 155px;
                box-sizing: border-box;
                border-bottom: 1px solid #dddddd;
                display: flex;
                flex-direction: column;
                h4{
                    height: 24px;
                    margin-bottom: 8px;
                    line-height: 24px;
                    display: flex;
                    align-items: center;
                    span{
                        font-size: 15px;
                        font-weight: bold;
                        margin-right: 30px;
                    }
                }
                .address-detail{
                    color: #585c64;
                    font-size: 14px;
                    white-space: pre-wrap;
                }
                .time-detail{
                    color: #585c64;
                    font-size: 14px;
                    margin-top: 11px;
                }
                .manage-address{
                    margin-top:8px;
                    display: flex;
                    justify-content: flex-end;
                    height: 20px;
                    div{
                        color: #3d92fb;
                        font-size: 14px;
                        width: 40px;
                        height: 20px;
                        line-height: 20px;
                        margin-left: 20px;
                        margin-right: 5px;
                    }
                }
            }
        }
        .add-address{
            height: 92px;
            padding: 25px 50px;
            background: #fff;
            box-sizing: border-box;
            div{
                border: 1px solid #dddddd;
                line-height: 42px;
                text-align: center;
                width: 100%;
                font-size: 14px;
                color: #565656;
            }
        }
    }
}
</style>